//
//  publishView.m
//  YiXiu
//
//  Created by ZHY on 16/7/12.
//  Copyright © 2016年 zzz. All rights reserved.
//

#import "publishView.h"
#import "BaseViewController.h"
#import "FeedbackController.h"
#import "pubVoiseViewController.h"
#define kImageTitleX 54
#define kImageVoiceWH 85
#define kImageVoiceY KScreenHeight -kImageVoiceWH-216
#define kVoiceX KScreenWidth -kImageTitleX-kImageVoiceWH


@interface publishView ()

@property (nonatomic, strong) UIView *publishView;
@property (nonatomic, strong) UIButton  *imgTitView;
@property (nonatomic, strong) UIButton  *voiceBtn;
@property (nonatomic, strong) UIButton  *backBtn;

@end

@implementation publishView

-(instancetype)initWithFrame:(CGRect)frame{
    
    
        if (self  = [super initWithFrame:CGRectMake(0, KScreenHeight * 2, KScreenWidth, KScreenHeight)] ) {
            
            UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
            //点击两次
            tap.numberOfTapsRequired = 2;
            //设置视图的透明度
            self.alpha = 0.85;
            //设置视图的颜色
            self.backgroundColor = [UIColor blackColor];
            [self addGestureRecognizer:tap];
            [self setUpImgTitView];
            [self setUpVoiceBtn];
            [self addSubview:self.backBtn];
            
        }
    return self;
}

-(void)setUpImgTitView{
    
    if (!_imgTitView) {
        _imgTitView= [[UIButton alloc]initWithFrame:CGRectMake(kImageTitleX, kImageVoiceY, kImageVoiceWH, kImageVoiceWH)];
//        _imgTitView.layer.cornerRadius = 10;
        [_imgTitView setImage:[UIImage imageNamed:@"tuwen"] forState:UIControlStateNormal];
        [_imgTitView addTarget:self action:@selector(TitAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_imgTitView];
    }
}

-(void )setUpVoiceBtn{
    
    if (!_voiceBtn) {
        _voiceBtn = [[UIButton alloc]initWithFrame:CGRectMake(kVoiceX, kImageVoiceY, kImageVoiceWH, kImageVoiceWH)];
//        _voiceBtn.layer.cornerRadius = 10;
        [_voiceBtn setImage:[UIImage imageNamed:@"fabuzhu"] forState:UIControlStateNormal];
        [_voiceBtn addTarget:self action:@selector(voiceAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_voiceBtn];
        }
}

-(UIButton *)backBtn{
    if (!_backBtn) {
        _backBtn = [[UIButton alloc]initWithFrame:CGRectMake((KScreenWidth - 60)/2,KScreenHeight-75-42.5 , 42.5, 42.5)];
        
        [_backBtn setImage:[UIImage imageNamed:@"quxiao"] forState:UIControlStateNormal];
        [_backBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _backBtn;
    
}

-(void)backAction:(UIButton *)sender{

    [UIView animateWithDuration:1 animations:^{
        
        self.frame = CGRectMake(0, KScreenHeight *2, KScreenWidth, KScreenHeight);
       
    }];

}

- (void)tapAction:(UITapGestureRecognizer *)tap{
    
    
    [UIView animateWithDuration:1 animations:^{
        
         self.frame = CGRectMake(0, KScreenHeight *2, KScreenWidth, KScreenHeight);
    
    }];
}
//图文的点击时间
-(void)TitAction:(UIButton *)sender{
//    
    if (self.block) {
        
        UIViewController * Vc = [[FeedbackController alloc]init];
        self.block(Vc);
    
        [self dismissAndCompletion:nil];
    }
}
//声音的点击时间
-(void)voiceAction:(UIButton *)sender{
    
    if (self.block) {
        
        UIViewController * Vc = [[pubVoiseViewController alloc]init];
        self.block(Vc);
        
        [self dismissAndCompletion:nil];
    }
}

-(void)dismissAndCompletion:(DisMissBlock)block{


    [UIView animateWithDuration:1 animations:^{
        self.frame =  CGRectMake(0, KScreenHeight * 2, KScreenWidth, KScreenHeight);
    } completion:^(BOOL finished) {
        if (block) {
            block();
        }
    }];
}

-(void)showAndCompletion:(DisMissBlock)block{
    
    
    [UIView animateWithDuration:1 animations:^{
        self.frame =  CGRectMake(0, 0, KScreenWidth, KScreenHeight);
    } completion:^(BOOL finished) {
        if (block) {
            block();
        }
        
    }];
    
}



@end
